<template>
  <a-modal v-model='visible' centered @cancel='handleCancel' width='900px'>
    <f-print tableShow ref='easyPrint' v-if='printType==1' :beforePrint='beforePrint'>
      <template slot-scope='func'>
        <order-print :tableData='printData' :getChineseNumber='func.getChineseNumber'></order-print>
      </template>
    </f-print>
    <f-print tableShow ref='easyPrint' v-if='printType==2' :beforePrint='beforePrint'>
      <template slot-scope='func'>
        <payment-print :tableData='printData' :getChineseNumber='func.getChineseNumber'></payment-print>
      </template>
    </f-print>
    <f-print tableShow ref='easyPrint' v-if='printType==3' :beforePrint='beforePrint'>
      <template slot-scope='func'>
        <invoice-print :tableData='printData' :getChineseNumber='func.getChineseNumber'></invoice-print>
      </template>
    </f-print>
    <f-print tableShow ref='easyPrint' v-if='printType==4' :beforePrint='beforePrint'>
      <template slot-scope='func'>
        <renkuan-print :tableData='printData' :getChineseNumber='func.getChineseNumber'></renkuan-print>
      </template>
    </f-print>
    <f-print tableShow ref='easyPrint' v-if='printType==5' :beforePrint='beforePrint'>
      <template slot-scope='func'>
        <back-order-print :tableData='printData' :getChineseNumber='func.getChineseNumber'></back-order-print>
      </template>
    </f-print>
    <f-print tableShow ref='easyPrint' v-if='printType==6' :beforePrint='beforePrint'>
      <template slot-scope='func'>
        <hui-kuan-print :tableData='printData' :getChineseNumber='func.getChineseNumber'></hui-kuan-print>
      </template>
    </f-print>
    <f-print tableShow ref='easyPrint' v-if='printType==7' :beforePrint='beforePrint'>
      <template slot-scope='func'>
        <settle-pay-print :tableData='printData' :getChineseNumber='func.getChineseNumber'></settle-pay-print>
      </template>
    </f-print>
    <template slot='footer'>
      <span v-if='showPrint==false'>打印次数:<span style='margin-left: 5px'>{{printTag}}</span></span>
      <a-button @click='printSub' v-if='printTag==0 && showPrint==true'>打印</a-button>
      <a-button @click="printSub" v-if="printTag>=1 && showPrint==true">重新打印({{printTag}})</a-button>
      <!-- <a-button v-if="showPrint==0">禁止打印</a-button>-->
    </template>
  </a-modal>
</template>

<script>
import OrderPrint from "./order_print"
import PaymentPrint from "./payment_print"
import InvoicePrint from "./invoice_print"
import RenkuanPrint from "./renkuan_print"
import HuiKuanPrint from "./huikuan_print"
import SettlePayPrint from "./settle_pay_print"
import api from "./../js/api"
import BackOrderPrint from "./back_order_print"

export default {
  name: "PrintModal",
  components: { BackOrderPrint, InvoicePrint, SettlePayPrint,PaymentPrint, HuiKuanPrint,OrderPrint, RenkuanPrint },
  props: {
    showPrint: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      api: Object.assign(api, this.api),
      visible: false,
      printTag: 0,
      printData: {},
      params: {},
      printType: 0
    }
  },
  created() {

  },
  methods: {
    handleCancel() {
      this.visible = false
      this.printTag = 0
    },
    printSub() {
      this.$refs.easyPrint.print()
      this.visible = false
    },
    beforePrint() {
      const url = this.params.url
      this.http.post(this, {
        url: url,
        data: this.params
      })
    },
    open(businessKey, printType, amountType) {
      let params = {}
      let url = ""
      //发货单
      if (printType == 1) {
        params.orderId = businessKey
        url = this.api.hyorder.getPrintInfo
        params.url = this.api.hyorder.updatePrintTag
      }
      //
      if (printType == 2) {
        params.paymentId = businessKey
        params.amountType = amountType
        url = this.api.payment.getHyPrintInfo
        params.url = this.api.payment.updatePrintTag
      }
      //开票税金
      if (printType == 3) {
        params.inoviceId = businessKey
        params.amountType = amountType
        url = this.api.payment.getInvoicePrintInfo
        params.url = this.api.payment.updatePrintTag
      }
      //认款单
      if (printType == 4) {
        params.paymentId = businessKey
        params.amountType = amountType
        url = this.api.payment.getRenkuanInfo
        params.url = this.api.payment.updatePrintTag
      }
      //退货单
      if (printType == 5) {
        params.orderId = businessKey
        url = this.api.hyorder.getBackOrderPrintInfo
        params.url = this.api.hyorder.updatePrintTag
      }
      //回款认款
      if (printType == 6) {
        params.paymentId = businessKey
        params.amountType = amountType
        url = this.api.payment.getHuikuanInfo
        params.url = this.api.payment.updatePrintTag
      }
      if (printType == 7) {
        params.paymentId = businessKey
        params.amountType = amountType
        url = this.api.payment.getHyPrintInfo
        params.url = this.api.payment.updatePrintTag
      }
      this.params = params
      this.http.get(this, {
        url: url,
        params: params,
        success: function(me, data) {
          me.$nextTick(() => {
            me.printData = data
            me.printType = printType
            if (data.printTag >= 1) {
              me.printTag = data.printTag
            }
            me.visible = true
          })
        }
      })
    }
  }
}
</script>
<style scoped media='print'>
@page {
  size: auto;
  margin-top: 5mm;
  margin-left: 5mm;
  margin-right: 5mm;
}

html {
  background-color: #ffffff;
  margin: 0px;
}

body {
  border: solid 1px #ffffff;
  margin: 0
}
</style>

